<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>字符串</title>
    <script>
        function f1(){
            let s = " Hello World ";
            console.log(s.length)
            // 去除首尾的空格
            s = s.trim();
            console.log(s.length)
            console.log(s.toUpperCase())
            console.log(s.toLowerCase())
            console.log(s.charAt(2));
            console.log(s.charAt(6));
            console.log(s.substring(6))
            // 左闭右开
            console.log(s.substring(2,7))
            s = "admin and jack and tom and lucy and lily and alex and john and alice"
            // 是否包含
            console.log(s.includes("and"))
            console.log(s.indexOf("and"))
            console.log(s.length)
            console.log(s.lastIndexOf("and"))
            // 替换第一次出现的
            console.log(s.replace("and","-"))
            // 替换所有
            console.log(s.replaceAll("and","-"))
        }

        function f2(){
            // let s = "123";
            // let s = "123.45";
            // let s = "123abc.45";
            // let s = "12abc345";
            let s = "abc345";
            s = parseInt(s);
            console.log(s);
        }
        function f3(){
            // let s = "123.45";
            // let s = "123.4ab5";
            // let s = "123.ab45";
            let s = "123.45.67";
            s = parseFloat(s);
            console.log(s)
        }
    </script>
</head>
<body>
<button onclick="f1()">常用属性与方法</button><br>
<button onclick="f2()">转换整数</button><br>
<button onclick="f3()">转换小数</button><br>
</body>
</html>